<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>账单管理</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
        .container {
            max-width: 400px; /* 适合手机屏幕 */
            width: 100%;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
            text-align: center;
        }
        h1 {
            color: #333;
            font-size: 1.8em;
            margin-bottom: 15px;
        }
        .input-group {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        input[type="text"] {
            width: 48%; /* 两个输入框各占一半空间 */
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 0.9em;
        }
        button {
            background-color: #007bff; /* 蓝色按钮 */
            color: white;
            padding: 8px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.9em;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #0056b3; /* 悬停时的深蓝色 */
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 15px;
        }
        th, td {
            padding: 8px;
            text-align: left;
            border-bottom: 1px solid #ddd;
            font-size: 0.9em;
        }
        th {
            background-color: #f2f2f2;
            font-weight: bold;
        }
        .total {
            margin-top: 15px;
            font-size: 1.1em;
            font-weight: bold;
        }
    </style>
</head>
<body>
<div id="app" class="container">
    <h1>账单管理</h1>
    <div class="input-group">
        <input type="text" v-model="name" placeholder="消费名称">
        <input type="text" v-model="price" placeholder="消费价格">
    </div>
    <button @click="add" @keyup.enter="enter">添加账单</button>

    <table>
        <tr>
            <th>编号</th>
            <th>消费名称</th>
            <th>消费价格</th>
            <th>操作</th>
        </tr>
        <tr v-for="(item, index) in zhangDan" :key="index">
            <td>{{index + 1}}</td>
            <td>{{item.name}}</td>
            <td>{{item.price}}</td>
            <td><button @click="del(index)">删除</button></td>
        </tr>
    </table>
    <div class="total">
        消费总计：{{total}}
    </div>
</div>

<script src="./js/vue.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            name: '',
            price: '',
            zhangDan: []
        },
        methods: {
            add() {
                if (this.name.trim() !== '' && this.price.trim() !== '') {
                    this.zhangDan.push({
                        name: this.name,
                        price: this.price
                    });
                    this.name = '';
                    this.price = '';
                }
            },
            del(index) {
                this.zhangDan.splice(index, 1);
            },
            enter(){
                this.add();
            }
        },
        computed: {
            total() {
                return this.zhangDan.reduce((total, item) => {
                    return total + Number(item.price);
                }, 0);
            }
        }
    });
</script>
</body>
</html>